1. Field of the Invention
The invention relates to a method and apparatus for image processing, and particularly, to an image processing method and apparatus for white balance correction.
2. Description of the Prior Art
In general, the color of an object will change with the color of the light illuminated on the object. This change can be automatically corrected by human eyes, but the optical sensor of a digital camera lacks this function. Thus, the photos taken under different lights generally have different color temperatures. For example, the photo taken in an environment illuminated by a tungsten lamp may be slightly yellow; the photo taken under the shadow may be slightly blue.
Many image processing systems have the function of white balance correction. The goal of white balance correction is to adjust the lightness of the three primary colors—red, green, and blue in a digital image to adjust the color error induced by the light. So that the photo taken by the digital camera can be closer to what human eyes see.
Determining the color temperature of the light source in an image is usually the first step of performing the white balance correction. The most traditional color temperature determining method is based on the gray world assumption proposed by R. M. Evans in 1946. A digital image is composed of a plurality of pixels. Each of the pixels has a red grey level, a green grey level, and a blue grey level respectively. According to the gray world assumption, under the normal color temperature, the average pixel values of the three colors red, green, and blue should be roughly equivalent. Thus, if the average value of certain color in an image is higher than the average values of the other two colors, the color of the image has a deviation due to the effect of the light.
In the color temperature determining method based on the gray world assumption, the average red value, the average green value, and the average blue value of all pixels in a digital image are firstly calculated. Then, the highest of the three average values is selected. If the red average value of certain image is higher than the green average value and blue average value, the image will be judged as slightly red. In other words, the color temperature of the light source in this image is slightly low.
However, the color of the object itself and the effect caused by the light in the image are not separately considered by the above-mentioned color temperature determining method. If the main object of an image is red even without the effect of external light, the color temperature of the light of the image can be incorrectly judged by the method and an incorrect white balance correction is performed thereafter.
Beside the RGB color space, the CIE color space is also a mode for showing colors. Referring to FIG. 1, FIG. 1 is a diagram of the CIE color space. The colors of the light sources of different temperatures can be marked on the CIE coordinate diagram. Connecting the marked points can obtain a curve 100 as shown in FIG. 1. The curve 100 is usually called the “black body locus” or “Plankian locus”. Roughly, the color temperature of the light source corresponding to the right side of the curve 100 is lower, and the color temperature of the light source corresponding to the left side of the curve 100 is higher.
In order to solve the above problem of incorrectly judging the color temperature, an existed color temperature determining method only considers the pixels around the curve 100 in the image when the color temperature of the light source of an image is judged, namely, only the pixels in the range 110 are considered. In the color temperature determining method, first, the red, green, and blue grey levels of all pixels in an image are converted into the CIE color space. Then, statistics of the amount of pixels in the range 110 are gathered. If there are more pixels on the right side of the range 110, the color temperature determining method will judge that the color temperature of the light source in the image is low.
The drawback of this method is that converting the red, green, and blue grey levels of all pixels into the CIE color space first is a trouble in calculation. Moreover, in practical applications, whether a pixel is in the range 110 is usually judged via the calculation of the distance between the pixel and the curve 100. Because the curve 100 is not a regular line, it is also very troublesome to calculate the distance between each of the pixels and the curve 100.
In order to solve the two problems above, another color temperature determining method is provided by U.S. Pat. Nos. 4,663,663 and 4,685,071. The Plankian locus has an exponential characteristic. Thus, through a proper logarithm conversion, the Plankian locus can be converted into a line in a logarithm coordinate. Referring to FIG. 2, the longitudinal axis and the transverse axis of the coordinate diagram are respectively Log(G/R) and Log(G/B), wherein R, G, B respectively represent the grey levels of the three colors red, green, and blue of a pixel. The curve 200 is converted from the Plankian locus, and is roughly a straight line. Correspondingly, the range 110 in FIG. 1 is also converted into the range 210 in FIG. 2.
The color temperature determining method provided by the two patents above is to gather statistics of the amount of the pixels in the range 210. If there are more pixels within the right side of the range 210, the color temperature of the light source of the image is judged to be low. The advantage of the method is that the red, green, blue grey levels need not to be converted into the CIE color space. The drawback of the invention is that it is still troublesome to calculate the distances between each of the pixels and the curve 200.